package com.ruoyi.framework.config;


import com.ruoyi.common.config.Global;
import com.ruoyi.framework.interceptor.ApiInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {

    /**
     * 解决本地图片转网络路径问题
     * @param registry
     * @date 2019/7/10 13:53
     * @author shihx
     * @return
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("/uploadPath/**").addResourceLocations("file:"+ Global.getProfile()+ "/");
    }

    @Bean
    public ApiInterceptor myInterceptor(){
        return new ApiInterceptor();
    }

    /**
     * 给接口添加拦截器
     * @param registry
     * @date 2019/7/10 13:54
     * @author shihx
     * @return
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor()).addPathPatterns("/api/**");
        super.addInterceptors(registry);
    }

}
